﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Biz;
using System.Data.Entity;
namespace BusinessLayer.Dal
{
    public class PropertyDal
    {
        DatabaseContext db;
        public PropertyDal(/* DatabaseContext db */)
        {
            this.db = DatabaseContext.DB;
        }

        public int Insert(Property property)
        {
            db.Properties.Add(property);
            return db.SaveChanges();
        }

        public int Update(Property property)
        {
            db.Entry(property).State = EntityState.Modified;
            return db.SaveChanges();
        }

        public int Delete(Property property)
        {
            db.Properties.Remove(property);
            return db.SaveChanges();
        }

        public static List<Property> GetByCategory(Category cat)
        {
            return DatabaseContext.DB.Properties.Where(c => c.Category.Id == cat.Id).ToList();
        }
    }
}
